package com.aduerr.v1shouyin.mvp.activity;

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.aduerr.v1shouyin.R;
import com.aduerr.v1shouyin.mvp.fragment.*;

import java.util.ArrayList;

public class HexiaoJiluActivity extends AppCompatActivity {

    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tb_hexiao)
    com.androidkun.xtablayout.XTabLayout tbHexiao;
    @BindView(R.id.vp_hexiao)
    ViewPager vpHexiao;
    private Mypager mypager;
    private ArrayList<Fragment> fragments;

    public ViewPager getVpHexiao() {
        return vpHexiao;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hexiao_jilu);
        ButterKnife.bind(this);
        initUI();
    }


    private void initUI() {
        tvTitle.setText("核销记录");
        fragments = new ArrayList<>();
//        HeXiaoAllFregmenet.newInstance();

//        fragments.add(new HeXiaoAllFregmenet());
        fragments.add(new YouhuiFragment());
        fragments.add(new DaijinFragment());
        fragments.add(new ZhekouFragment());
        fragments.add(new TimeCardsFragment());
        fragments.add(new TuanGouFragment());
        fragments.add(new LiPinFragment());
        fragments.add(new DiYongFragment());
        //团购
        fragments.add(MenPiaoFragment.newInstance(2));
        //门票
        fragments.add(MenPiaoFragment.newInstance(0));
        //酒店
        fragments.add(MenPiaoFragment.newInstance(1));


//        fragments.add(new HeXiaoAllKouBeiFregmenet());

        mypager = new Mypager(getSupportFragmentManager());
//        mypager.addfragment(fragments);
        vpHexiao.setAdapter(mypager);
        //联动
        tbHexiao.setupWithViewPager(vpHexiao);
        vpHexiao.setOffscreenPageLimit(1);
    }

    @OnClick(R.id.img_back)
    public void onViewClicked() {
        finish();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    class Mypager extends FragmentPagerAdapter {
        ArrayList<String> titles = new ArrayList<>();
//        ArrayList<Fragment> fragments = new ArrayList<>();

        public Mypager(FragmentManager fm) {
            super(fm);
//            titles.add("全部");
            titles.add("优惠券");
            titles.add("代金券");
            titles.add("折扣券");
            titles.add("次卡券");
            titles.add("团购券");
            titles.add("礼品券");
            titles.add("抵用券");
            titles.add("线下团购券");
            titles.add("门  票");
            titles.add("酒  店");

//            titles.add("口碑券");
        }

        @Override
        public int getCount() {
            return titles != null ? titles.size() : 0;
        }

        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return titles.get(position);
        }
    }
}
